import { useLocation } from '@solidjs/router'
import { memo } from 'solid-js/web'
import { createMemo } from 'solid-js'
import routes from '@/routes'

export function useMenu() {
  const navbarList = () => routes.filter(v => v?.children) || []

  const menuList = () => {
    const current = useLocation().pathname.split('/')?.[1]
    const list = navbarList().find(v => v.path.includes(current))
    return list?.children.map((v => ({
      ...v,
      path: `${list.path}${v.path}`,
    })))
  }

  return { navbarList, menuList }
}
